package com.qf.web;

import com.qf.bean.Users;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.ServletContext;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.List;

/**
 * 2019/11/16
 * Administrator
 * springmvc1116
 * 面向对象面向君  不负代码不负卿
 */

//作用等价于servlet，但是不需要继承任何类
@Controller
public class ControllerA {
   //使用斜杠直接传参
    //原来:testa?uname=张三&age=20
    //现在:testa/张三/20
    //params 设置该请求中必须添加名为对应变量的key值
   // @RequestMapping(value = "/testa/{a2}/{b1}",params = {"abc"})
   @RequestMapping(value = "/testa/{a2}/{b1}")
    public String a(@PathVariable("a2") String name,
                    @PathVariable("b1") int age,
                    @RequestHeader("Accept") String str,HttpServletResponse response ){
        System.out.println(name+"...."+age);
        System.out.println("str="+str);

        //创建cookie
        Cookie cookie = new Cookie("uname","lisi");
        cookie.setMaxAge(60*60);
        cookie.setPath("/");
        response.addCookie(cookie);
        return "success";
    }

    //获得cookie中的值
    @RequestMapping("/testc")
    public String aaa(@CookieValue("JSESSIONID") String string,@CookieValue("uname") String name){
        System.out.println("aaaa="+string);
        System.out.println("uname="+name);
        return "success1";
    }
}
